{%extends 'layout.admin.html'%}
{%block content%}
{% load authfilters %}

  <script src="/dist/js/json-preview.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/header@latest"></script><!-- Header -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/simple-image@latest"></script><!-- Image -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/delimiter@latest"></script><!-- Delimiter -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/list@latest"></script><!-- List -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/checklist@latest"></script><!-- Checklist -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/quote@latest"></script><!-- Quote -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/code@latest"></script><!-- Code -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/embed@latest"></script><!-- Embed -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/table@latest"></script><!-- Table -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/link@latest"></script><!-- Link -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/warning@latest"></script><!-- Warning -->

  <script src="https://cdn.jsdelivr.net/npm/@editorjs/marker@latest"></script><!-- Marker -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/inline-code@latest"></script><!-- Inline Code -->

  <!-- Load Editor.js's Core -->
  <script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>

<div class="page-header d-print-none">
  <div class="container-xl">
    <div class="row g-2 align-items-center">
      <div class="col">
        <h1 class="page-title">Editor.js</h1>
        <h4 class="seo-h1">
Editor.js revolutionizes content creation with its innovative ​​block-style editing​​ experience. Unlike traditional WYSIWYG editors that output messy HTML, Editor.js structures content into independent, customizable blocks (paragraphs, headings, images, lists, quotes, etc.), each acting as a distinct content element. This modular approach provides unparalleled flexibility and control. Crucially, Editor.js ​​outputs clean, structured JSON data​​ instead of raw HTML. This separates pure content from presentation, making your data instantly ready for diverse applications: render seamlessly on websites, power mobile apps, generate AMP/Facebook Instant Articles, or even create audio versions. The JSON output is ​​optimized for backend processing​​, simplifying sanitization, validation, and storage. Built with extensibility in mind, Editor.js boasts a ​​simple, powerful API​​ enabling developers to create custom blocks for any need – integrate social media embeds (Tweets, Instagram), polls, CTA buttons, or unique interactive elements. Experience a stable, mature platform refined over years of real-world use by major media projects. Enjoy the efficiency of a truly ​​block-oriented workspace​​ and harness the power of ​​structured content delivery​​ for modern web and application development. Explore the demo and see how Editor.js elevates your content workflow.
        </h4>
      </div>
    </div>
  </div>
</div>

<div class="page-body">
    <div class="container-xl">
        <div class="row row-cards">
             <div class="col-md-6">
                <div class="card">
                  <div class="card-body">
                    <div id="editorjs"></div>
                  </div>
                </div>
             </div>
             <div class="col-md-6">
                <div class="card">
                    <div class="card-body">
                        <h4>Json Output</h4>
                        <a href="{{host}}" onclick="return cpy(this);" style="float:right; margin-top:-2rem;" class="badge badge-outline text-secondary fw-normal badge-pill">Copy</a>
                        <div>
                            <pre style="max-height:1700px; overflow:auto;"><code id="output"></code></pre>
                        </div>
                    </div>
                </div>
             </div>
       </div>
    </div>
</div>
<script type='text/javascript'>

const editor = new EditorJS({ 
    holder: 'editorjs', 
    readOnly: false,
    autofocus: true,

    tools: { 
        header: {
          class: Header,
          inlineToolbar: ['marker', 'link'],
          config: {
            placeholder: 'Header'
          },
          shortcut: 'CMD+SHIFT+H'
        }, 

        image: SimpleImage,

        list: {
          class: EditorjsList,
          inlineToolbar: true,
          shortcut: 'CMD+SHIFT+L'
        },

        checklist: {
          class: Checklist,
          inlineToolbar: true,
        },

        quote: {
          class: Quote,
          inlineToolbar: true,
          config: {
            quotePlaceholder: 'Enter a quote',
            captionPlaceholder: 'Quote\'s author',
          },
          shortcut: 'CMD+SHIFT+O'
        },

        warning: Warning,

        marker: {
          class:  Marker,
          shortcut: 'CMD+SHIFT+M'
        },

        code: {
          class:  CodeTool,
          shortcut: 'CMD+SHIFT+C'
        },

        delimiter: Delimiter,

        inlineCode: {
          class: InlineCode,
          shortcut: 'CMD+SHIFT+C'
        },

        linkTool: LinkTool,

        embed: Embed,

        table: {
          class: Table,
          inlineToolbar: true,
          shortcut: 'CMD+ALT+T'
        },
    },
    onReady: function(){
        output();
    },

    onChange: function(api, event) {
        console.log('something changed', event);
        output();
    },

    data: {
        blocks: [
          {
            type: "header",
            data: {
              text: "Editor.js",
              level: 2
            }
          },
          {
            type : 'paragraph',
            data : {
              text : 'Hey. Meet the new Editor. On this page you can see it in action — try to edit this text. Source code of the page contains the example of connection and configuration.'
            }
          },
          {
            type: "header",
            data: {
              text: "Key features",
              level: 3
            }
          },
          {
            type : 'list',
            data : {
              items : [
                'It is a block-styled editor',
                'It returns clean data output in JSON',
                'Designed to be extendable and pluggable with a simple API',
              ],
              style: 'unordered'
            }
          },
          {
            type: "header",
            data: {
              text: "What does it mean «block-styled editor»",
              level: 3
            }
          },
          {
            type : 'paragraph',
            data : {
              text : 'Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class=\"cdx-marker\">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.'
            }
          },
          {
            type : 'paragraph',
            data : {
              text : `There are dozens of <a href="https://github.com/editor-js">ready-to-use Blocks</a> and the <a href="https://editorjs.io/creating-a-block-tool">simple API</a> for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.`
            }
          },
          {
            type: "header",
            data: {
              text: "What does it mean clean data output",
              level: 3
            }
          },
          {
            type : 'paragraph',
            data : {
              text : 'Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below'
            }
          },
          {
            type : 'paragraph',
            data : {
              text : `Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.`
            }
          },
          {
            type : 'paragraph',
            data : {
              text : 'Clean data is useful to sanitize, validate and process on the backend.'
            }
          },
          {
            type : 'delimiter',
            data : {}
          },
          {
            type : 'paragraph',
            data : {
              text : 'We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make its core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏'
            }
          },
          {
            type: 'image',
            data: {
              url: 'dist/img/editorjs.jpeg',
              caption: '',
              stretched: false,
              withBorder: true,
              withBackground: false,
            }
          },
        ]
      }
});

function output() {
  editor.save()
    .then((savedData) => {
      cPreview.show(savedData, document.getElementById("output"));
    })
    .catch((error) => {
      console.error('Saving error', error);
    });
}

function cpy(obj) {
    obj.text = 'Copied!'

    setTimeout(function() {
        obj.text = 'Copy';
    }, 1000);

    //实现js复制功能
    navigator.clipboard.writeText(document.getElementById("output").innerText);
    return false;
}
</script>
{%endblock%}
